<template>
  <div>
    <el-input-number v-model="begin" :precision="2" :step="1" :max="99999" />
    <el-input v-model="name" style="width: 500px;" placeholder="请输入书名" />
    <el-input-number v-model="end" :precision="2" :step="1" :max="99999" />
    <el-row style="margin-top: 30px">
      <el-button type="primary" @click="download(begin,name,end),clickHandler($event)">下载图书信息<i class="el-icon-download el-icon--right" /></el-button>
    </el-row>
  </div>
</template>

<script>

import userApi from '@/api/user'
export default {
  data() {
    return {
      begin: 0,
      name: '',
      end: 0
    }
  },

  methods: {
    download(begin, name, end) {
      if (begin === 0 && end === 0 && name === '') {
        userApi.downloadAll().then(res => {
          const result = res.data // 如果后端返回的result是进过Blob处理的，直接 window.URL.createObjectURL(result)，如果没有，就需要先实例化new Blod处理之后再window.URL.createObjectURL(blob)。
          const blob = new Blob([result], { type: 'application/vnd.ms-excel' })
          const url = window.URL.createObjectURL(blob)
          const link = document.createElement('a')
          link.download = 'product.xls'
          link.href = url
          link.click()
        })
      } else {
        userApi.download(begin, name, end).then(res => {
          const result = res.data // 如果后端返回的result是进过Blob处理的，直接 window.URL.createObjectURL(result)，如果没有，就需要先实例化new Blod处理之后再window.URL.createObjectURL(blob)。
          const blob = new Blob([result], { type: 'application/vnd.ms-excel' })
          const url = window.URL.createObjectURL(blob)
          const link = document.createElement('a')
          link.download = 'product.xls'
          link.href = url
          link.click()
        })
      }
    }

  }

}
</script>

<style>

</style>
